<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//首页模型
class Home_model extends CI_Model
{
	public function get_rencent_news()
	{
		$this->db->select('aid,category.cid,catname,desc,image,title,new_window,addtime,cattype');
		$this->db->from('article');
		$this->db->join('category', 'category.cid = article.cid');
		$this->db->order_by("article.sort", "asc");
		$this->db->order_by("article.addtime", "desc");
		$this->db->limit(3);
		$data = $this->db->where(array('article.status'=>1))->get()->result_array();
		return $data;
	}

	public function get_five_notice()
	{
		$this->db->select('aid,cid,title,new_window,addtime');
		$this->db->order_by("sort", "asc");
		$this->db->order_by("addtime", "desc");
		$this->db->limit(5);
		$data = $this->db->get_where('article',array('status'=>1,'cid'=>59))->result_array();
		return $data;
	}

	public function get_five_lecture()
	{
		$this->db->select('aid,cid,title,new_window,addtime');
		$this->db->order_by("sort", "asc");
		$this->db->order_by("addtime", "desc");
		$this->db->limit(5);
		$data = $this->db->get_where('article',array('status'=>1,'cid'=>11))->result_array();
		return $data;
	}

	public function get_category_by_id($cid)
	{
		$tmpData = $this->db->select('cid,pid,catname,cattype')->get('category')->result_array();
		$categorys = channelLevel($tmpData);
		return $categorys[$cid];
	}

	public function get_article_by_category($cid,$perpage,$offset)
	{
		$this->db->select('aid,cid,title,addtime');
		$this->db->order_by("sort", "asc");
		$this->db->order_by("addtime", "desc");
		$this->db->where(array('cid'=>$cid,'status'=>1));
		$data = $this->db->get('article',$perpage,$offset)->result_array();
		return $data;
	}

	public function get_count($cid)
	{
		$table = 'article';
		$cou = $this->db->where(array('cid'=>$cid,'status'=>1))->count_all_results($table);
		return $cou;
	}

	public function get_ainfo_by_aid($aid)
	{
		$this->db->select('*');
		$this->db->where(array('aid'=>$aid,'status'=>1));
		$data = $this->db->get('article')->row_array();
		return $data;
	}

	public function get_ainfo_by_cid($cid)
	{
		$this->db->select('*');
		$this->db->where(array('cid'=>$cid,'status'=>1));
		$this->db->limit(1);
		$data = $this->db->get('article')->row_array();
		return $data;	
	}

	public function get_all_struct()
	{
		$this->db->select('*');
		$data = $this->db->get('structure')->result_array();
		return $data;
	}

	public function get_all_links()
	{
		$this->db->select('*');
		$data = $this->db->get('links')->result_array();
		return $data;	
	}

	public function get_people_count($cid)
	{
		$table = 'people';
		$cou = $this->db->where(array('c_id'=>$cid,'pe_status'=>1))->count_all_results($table);
		return $cou;
	}

	public function get_people_by_cid($cid,$perpage,$offset)
	{
		$this->db->select('pe_id,c_id,pe_name,pe_term,pe_image,pe_duty,pe_sec_title,pe_email,pe_office');
		$this->db->order_by("pe_sort", "asc");
		$this->db->order_by("pe_name", "asc");
		$this->db->where(array('c_id'=>$cid,'pe_status'=>1));
		$data = $this->db->get('people',$perpage,$offset)->result_array();
		return $data;
	}

	public function get_info_by_peid($peid)
	{
		$this->db->select('*');
		$this->db->where(array('pe_id'=>$peid,'pe_status'=>1));
		$this->db->limit(1);
		$data = $this->db->get('people')->row_array();
		return $data;
	}
}